
'use strict'

class like{
  constructor(){
    this.param = '/'
  }

  async get(c){
    let a = c.service.fun;
    let {user_id,article_id} = c.query;
    console.log(user_id);
    //console.log(article_id);
    c.setHeader('content-type', 'text/html; charset=utf-8')
    let liked_uid =await a.sel('article_list',{'article_id':`${article_id}`},['poster_id'],c.service.pool);
    //console.log(liked_uid.rows[0])
    let {poster_id} = liked_uid.rows[0];
    let data1 = await a.sel('like_list',{'like_user_id':`${user_id}`},['liked_article_id'],c.service.pool)
    let aa = data1.rows.some(item=>{
      return article_id == item.liked_article_id
    })
    if(aa){
     
      a.del('like_list',{'liked_article_id':`${article_id}`,like_user_id:`${user_id}`},c.service.pool)
      c.send('no')
    }else{
      a.add('like_list',{'liked_article_id':`${article_id}`,'iflike':true,'liked_user_id':`${poster_id}`,'like_user_id':`${user_id}`},c.service.pool);
      c.send('ok')
    }
    
  }
}
module.exports = like;
